<?php

namespace app\common\model;

use app\common\exception\Exception;
use think\Db;
use think\Hook;
use think\Model;
use traits\model\SoftDelete;

/**
 * 审批流动作
 */
class ApprovesAction extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [

    ];

    //审批状态:1=同意,0=拒绝

    /*
     * 审批动作添加
     * $approve 审批流
     * $oper 审批用户
     * $type 审批用户类型
     * $remark 审批备注
     * $status 审批状态，1=同意，0=拒绝
     */
    public static function operAdd($approve=null, $oper=null, $type='user', $status=1, $remark='')
    {
        $oper_id = empty($oper) ? 0 : (is_array($oper) ? $oper['id'] : $oper->id);
        $self = new self();
        $self->approves_id = $approve['id'];
        $self->oper_type = $type;
        $self->oper_id = $oper_id;
        $self->status = $status;
        $self->remark = $remark;
        $self->save();

        return $self;
    }


}
